package com.weina.service.impl;

import com.weina.dao.RoleMapper;
import com.weina.entity.Role;
import com.weina.service.RoleService;
import com.weina.vo.RoleVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class RoleServiceImpl implements RoleService {
    @Resource
    private RoleMapper roleMapper;

    @Override
    public List<Role> findRoleList(RoleVo roleVo) {
        return roleMapper.findRoleList(roleVo);
    }

    @Override
    public int addRole(Role role) {
        return roleMapper.addRole(role);
    }

    @Override
    public int updateRole(Role role) {
        return roleMapper.updateRole(role);
    }

    @Override
    public int deleteRole(Integer id) {
        return roleMapper.deleteRoleById(id);
    }

    @Override
    public int saveRoleMenu(String mids, Integer roleId) {
        try {
            //删除角色菜单中间表中当前角色的旧的数据
            roleMapper.deleteRoleMenu(roleId);
            String[] midsArr=mids.split(",");
            for(int i=0;i<midsArr.length;i++){
                roleMapper.addRoleMenu(midsArr[i],roleId);
            }
            return 1;
        } catch (Exception e) {
            e.printStackTrace();
        }
        //保存当前角色所拥有的权限
        return 0;
    }

    //查询所有角色列表
    @Override
    public List<Map<String, Object>> findRoleListByMap() {
        return roleMapper.findRoleListByMap();
    }
    //查询当前用户你角色列表
    @Override
    public List<Integer> findCurrentEmpRoleList(Integer eid) {
        return roleMapper.findEmployeRoleByEmployeeId(eid);
    }


}
